//
//  HBAgreementCtrl.m
//  HuoBao
//
//  Created by 于会海 on 15/11/26.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBAgreementCtrl.h"

#import "HBGetUserRegistUrlInfo.h"
#import "HBGetUserRegistUrlParam.h"
#import "HBGetUserRegistUrlParser.h"
@interface HBAgreementCtrl ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView* agreeWeb;

@end

@implementation HBAgreementCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)buildLayout{
    self.view.backgroundColor = [LCCommon getColor:@"262626"];
    self.title = @"注册服务协议";
    
    self.agreeWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
    self.agreeWeb.delegate = self;
    [self.view addSubview:self.agreeWeb];
    
    [self requestToGetDeal];
}

- (void)requestToGetDeal{
    HBGetUserRegistUrlParam* param = [[HBGetUserRegistUrlParam alloc] init];
    HBGetUserRegistUrlParser* parser = [[HBGetUserRegistUrlParser alloc] init];
    [NetCenter getDataFromURL:Method_getRegAgreementUrl params:param parser:parser result:^(ParserResult *myResult) {
        if (myResult.code==0){
            HBGetUserRegistUrlInfo *agreeInfo = (HBGetUserRegistUrlInfo *)myResult.result;
            [self.agreeWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:agreeInfo.dataInfo]]];
        }
        else{
            DISSMISS_ERR(myResult.message);
        }
        
    } failure:^(NSError *error) {
        DISSMISS_ERR(error.description);
    }];
}

#pragma mark - webViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
   
    return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    [LCLoadingView hideLoadingViewForView:self.view];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
//    [LCLoadingView hideLoadingViewForView:self.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    [self.agreeWeb stopLoading];
    self.agreeWeb.delegate = nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
